1. Field of the Invention
The present invention relates generally to a data processing system and in particular to a method and system for managing variable assignments. More particularly, the present invention is directed to a computer-implemented method, apparatus, and computer-usable program code for managing variable assignments in a program.
2. Description of the Related Art
Computer programs often include variable assignments. A variable assignment is any programming statement in which a variable is assigned a value. The syntax used to assign a variable to a value differs depending on the programming language used to write the program. Non-limiting examples of programming languages that allow variable assignments include Fortran, C, C++, Java, Windows PowerShell, ALGOL, Pascal, Lisp, and COBOL.
Often, the assignment of a value to a variable occurs at a different point in a program than the point at which the variable is used. When program code exists between the point at which the variable is assigned and the point at which the variable is subsequently used, the value of the variable may be kept in a register across the intervening code, thereby preventing the intervening code from using the register during execution. Also, the point at which the variable is used may never occur during execution of the program. For example, the variable may be used in the “if” branch of an if/then statement in a program that executes the “else” branch of the if/then statement. In this example, the register used to store the value of the variable is wasted because the variable is not used during execution of the program.
Variable assignment sinking is an optimization technique used to improve the efficiency of a program by avoiding the unnecessary assignment of variables. Variable assignment sinking moves the variable assignment closer to one or more points in the program at which the assigned variable is used.
One current method for variable assignment sinking involves partial redundancy dataflow analysis to identify the exact locations where a variable assignment is live. A variable assignment is “live” if a program point that occurs after the variable assignment uses the value of the variable in the variable assignment. However, due to the complexity of partial redundancy dataflow analysis, which requires many steps, partial redundancy dataflow analysis is an impractical approach when compile time is an important factor.
Current methods for variable assignment sinking are sometimes used in an emulation environment, in which traces of instructions written for one computer architecture are translated to the instructions for a different, target computer architecture. However, these current methods, when used in an emulation environment, typically remove assignments to emulated state variables from an on trace path, such as condition code computations, via processor specific mechanisms. However, these processor specific mechanisms may not be general enough to be effectively implemented in a system that can target multiple processors.